package com.xhw.web.controller.result;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @Author xhw
 * @Date 2023/8/21
 * @Version 1.0
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor//不得行
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {

    private Boolean success;
    private T data;
    private String errorCode;
    private String message;

    public static <T> Result<T> error(final String errorCode, final String message) {
        return new Result<>(false, null, errorCode, message);
    }

    public static <T> Result<T> ok(final T data) {
        return new Result<>(true, data, null, null);
    }

    public static Result<Void> ok() {
        return new Result<>(true, null, null, null);
    }
}
